<?php
//$_GET['user_id']

	include 'include/function.php';
	
	$special_user=get_special_page_id('Users');
	if(!isset($_GET['user_id']))redirect('shownode.php?id=' . $special_user);
	
	$user_id=get_to_mysql($_GET['user_id']);
	$query="select * from user where id=$user_id ";
	$ret=oj_query($query);
	$row=mysql_fetch_assoc($ret);
	if(!isset($row['name']))redirect_error(_d('err_no_user'));

function userinfo_display($left,$right){
	echo '<tr>';
	echo "<td>$left:</td>";
	echo "<td class='bottomline'>$right</td>";
	echo '</tr>';
}
	
	$user_name	=htmlspecialchars($row['name']);
	$user_nick	=htmlspecialchars($row['nick_name']);
	$user_login	=htmlspecialchars($row['last_login_time']);
	$user_reg	=htmlspecialchars($row['reg_time']);
	$user_name_mysql	=mysql_real_escape_string($row['name']);
	$user_nick_mysql	=mysql_real_escape_string($row['nick_name']);

	show_header(_d('title_user'));
	
	//user node
	$query="select id from node where parent=$special_user and create_id=$user_id limit 1 ";
	$ret=oj_query($query);
	$row=mysql_fetch_row($ret);
	if(isset($row[0])) {
		$user_node=$row[0];
	} else {
		//开通用户节点
		$user_node=easy_insert_node($user_name_mysql,$user_nick_mysql,$special_user,$user_id,'no');
	}
	
?>
<table align="center">
	<tr>
		<td colspan="2" style='text-align:center;'>
			<h2 style="color:#538;"><?php echo $user_name ?></h2><br/>
<?php if(isset($_user_id))echo "<a href='message.php?action=write&rec_id=$user_id'>Send message</a>"; ?>
		</td>
	</tr>
<?php
	userinfo_display(_d('user_nick'),$user_nick);
	userinfo_display(_d('user_node'),"<a href='shownode.php?id=$user_node'>$user_name</a>");
	userinfo_display(_d('time_last_login'),$user_login);
	userinfo_display(_d('time_reg'),$user_reg);
	//user rate
	echo '<tr><td colspan="2" style="text-align:center;"><br/><b>' . _d('user_rated') . '</b></td></tr>';
	$query="select count(node_id),rate from user_rate where user_id=$user_id group by rate ";
	$ret=oj_query($query);
	$user_nrate=0;
	while($row=mysql_fetch_row($ret)) {
		if($_user_id==$user_id)
			userinfo_display(_d('ra_' . $row[1]),"<a href='search.php?rate={$row[1]}'>{$row[0]}</a>");
		else
			userinfo_display(_d('ra_' . $row[1]),$row[0]);
		$user_nrate+=(int)$row[0];
	}
	if($_user_id==$user_id)
		userinfo_display(_d('user_total'),"<a href='search.php?rate=all'>$user_nrate</a>");
	else
		userinfo_display(_d('user_total'),$user_nrate);
	//question
	echo '<tr><td colspan="2" style="text-align:center;"><br/><b>' . _d('user_question') . '</b></td></tr>';
	$query="select count(1) from request_permit where user_id=$user_id and state='accept' ";
	$ret=oj_query($query);
	$row=mysql_fetch_row($ret);
	userinfo_display(_d('user_q_accept'),$row[0]);
	
?>
</table>

<?php

	include 'include/footer.php';
?>

